package serialize

import "reflect"

// 将结构体指针转换为map
func StructPtrToMap(data interface{}) map[string]interface{} {
	result := make(map[string]interface{})

	val := reflect.ValueOf(data).Elem() // 解引用结构体指针
	typ := val.Type()

	for i := 0; i < val.NumField(); i++ {
		field := typ.Field(i)
		fieldName := field.Name
		fieldValue := val.Field(i).Interface()

		result[fieldName] = fieldValue
	}

	return result
}
